<?php

class InformModel
{
    private $informModelKeyPrefix   =   'I/';

    public function postInform($info)/*{{{*/
    {
        if (empty($info['informUid'])   ||  empty($info['informedUid']) ||  empty($info['informObject']) || empty($info['informType']))
        {
            empty($info['informUid'])       &&  AC::$errorNo    =   'IM001';
            empty($info['informedUid'])     &&  AC::$errorNo    =   'IM002';
            empty($info['informObject'])    &&  AC::$errorNo    =   'IM003';
            empty($info['informType'])      &&  AC::$errorNo    =   'IM004';

            return  FALSE;
        }

        $data   =   array();
        $data['informUid']          =   $info['informUid'];
        $data['informNickname']     =   $info['informNickname'];
        $data['informObject']       =   $info['informObject'];
        $data['informType']         =   $info['informType'];
        $data['informTime']         =   AC::SERVER_TIME;
        $data['status']             =   0;
        $data['informedUid']        =   $info['informedUid'];
        $data['informedNickname']   =   $info['informedNickname'];

        isset($info['informReason'])&&  $data['informReason']   =   $info['informReason'];
        isset($info['bodyType'])    &&  $data['bodyType']       =   $info['bodyType'];
        isset($info['bodyId'])      &&  $data['bodyId']         =   $info['bodyId'];

        $key    =   $this->informModelKeyPrefix. 0;
        $result =   Storage::addData($key, $data);

        return  $result;
    }/*}}}*/

    public function updateInform($info)/*{{{*/
    {
        if (empty($info['id'])  ||  empty($info['editorUid'])   ||  empty($info['status'])  ||  empty($info['dealResult']))
        {
            empty($info['id'])          &&  AC::$errorNo    =   'IM005';
            empty($info['editorUid'])   &&  AC::$errorNo    =   'IM006';
            empty($info['status'])      &&  AC::$errorNo    =   'IM007';
            empty($info['dealResult'])  &&  AC::$errorNo    =   'IM008';

            return  FALSE;
        }

        $data   =   array();
        $data['status']         =   $info['status'];
        $data['editorUid']      =   $info['editorUid'];
        $data['editorNickname'] =   $info['editorNickname'];
        $data['dealResult']     =   $info['dealResult'];

        $key    =   $this->informModelKeyPrefix. 0;
        $where  =   array('id' => $info['id']);
        $result =   Storage::setConditionData($key, $data, $where);
        return  $result;
    }/*}}}*/

    public function removeInform($info)/*{{{*/
    {
        if (empty($info['id']))
        {
            AC::$errorNo    =   'IM005';
            return  FALSE;
        }

        $key    =   $this->informModelKeyPrefix. $info['id'];
        $where  =   array('id'  =>  $info['id']);
        $result =   Storage::delConditionData($key, $where);

        return  $result;
    }/*}}}*/

    public function getInformList($info)/*{{{*/
    {
        $start  =   0;
        $where  =   NULL;
        $length =   AC::FEED_LIST_DISPLAY_LEN;
        isset($info['start'])       &&  $start                  =   $info['start'];
        isset($info['length'])      &&  $length                 =   $info['length'];
        isset($info['id'])          &&  $where['id']            =   $info['id'];
        isset($info['informUid'])   &&  $where['informUid']     =   $info['informUid'];
        isset($info['informType'])  &&  $where['informType']    =   $info['informType'];
        isset($info['informedUid']) &&  $where['informedUid']   =   $info['informedUid'];

        $orderBy=   ' id DESC ';
        $key    =   $this->informModelKeyPrefix. 0;
        $result =   Storage::getManyData($key, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/

}


